package com.gzcssutils;

import cn.hutool.core.util.IdUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import cn.hutool.db.ds.DSFactory;
import cn.hutool.db.handler.EntityListHandler;
import cn.hutool.db.sql.SqlExecutor;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

public class DbTest {

    private static Log log = LogFactory.get();

    public static void main(String[] args) {
        DataSource ds = DSFactory.get();
        Connection conn = null;
        try {
            conn = ds.getConnection();
            String TABLE_NAME = "gzcss_account";
            PreparedStatement ps = conn.prepareStatement("select * from " + TABLE_NAME + " where user_name = ? and mobile = ?");
            /* 执行查询语句，返回实体列表，一个Entity对象表示一行的数据，Entity对象是一个继承自HashMap的对象，存储的key为字段名，value为字段值 */
            List<Entity> entityList =  SqlExecutor.query(ps,new EntityListHandler(),new Object[] { "lqw","15902066476"});

            log.debug("{}",entityList);

        } catch (SQLException e) {
            e.printStackTrace();
        }

    }

}
